package servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import service.AreaTipsService;
import service.impl.AreaTipsServiceImpl;


public class AreaTipsServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	private AreaTipsService service;
   
    public AreaTipsServlet() {
    	service = new AreaTipsServiceImpl();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request,response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/json;charset=UTF-8");
		
		String input = request.getParameter("input");
		
		System.out.println("servlet get input = "+input);
		String output = this.service.parseInputAndReturnOutput(input);
		
		response.setHeader("Access-Control-Allow-Origin", "*");
		PrintWriter writer = response.getWriter();
		writer.write(output);
		writer.close();
	}
}
